package com.sgb.kjwl.view.ui.activity.self.logistics;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.sgb.alimaplibrary.util.ToastUtil;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityOfferOwnerDetailsBinding;
import com.sgb.kjwl.model.entity.self.AddField;
import com.sgb.kjwl.model.entity.self.OfferDetailsEntity;
import com.sgb.kjwl.model.entity.transport.OfferGoodsSourcePlaceEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.NumberUtil;
import com.sgb.kjwl.view.ui.adapter.transport.CarInfoAdapter;
import com.sgb.kjwl.view.widget.transport.InvoiceInfoBottomDialog;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LogisticsEvent;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.activity.transport.BiddingOrderDetailsActivity;
import com.sgb.kjwl.view.ui.activity.transport.owner.TransportOrderDetailOwnerActivity;
import com.sgb.link.view.widget.ExpandedTextView;
import com.sgb.kjwl.view.widget.TimeCountDown;
import com.sgb.kjwl.viewmodel.self.logistics.OfferOwnerDetailsModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.util.DateUtils;
import com.im.immodel.IMUtils;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.util.StringUtil;
import com.swgk.core.util.UserOperating;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Describe:    报价单位详情
 * Author:  yangLei
 * Date:    2021/4/8
 */
public class OfferOwnerDetailsActivity extends AppActivity {

    private ActivityOfferOwnerDetailsBinding binding;
    private TimeCountDown timeCount;
    OfferOwnerDetailsModel viewModel;
    private String offerNo;
    private OfferDetailsEntity entity;
    private ArrayList<String> attachmentImages;
    private boolean isGeneralGoods;
    private InvoiceInfoBottomDialog invoiceDialog;
    BottomSheetDialog carInfoWindow;

    public static void start(Context context, String offerNo, boolean isGeneralGoods) {
        Intent intent = new Intent(context, OfferOwnerDetailsActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra("offerNo", offerNo);
        intent.putExtra("isGeneralGoods", isGeneralGoods);//是否普通货源的报价详情
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        offerNo = getIntent().getStringExtra("offerNo");
        isGeneralGoods = getIntent().getBooleanExtra("isGeneralGoods", false);
        if (TextUtils.isEmpty(offerNo))
            finish();
        viewModel = new ViewModelProvider(this).get(OfferOwnerDetailsModel.class);

        binding = DataBindingUtil.setContentView(this, R.layout.activity_offer_owner_details);
        binding.topBar.titleView.setText("报价详情");
        binding.topBar.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
        binding.topBar.ivBack.setOnClickListener(v -> finish());
        binding.companyContactNumber.setOnClickListener(this);
        binding.contactNumber.setOnClickListener(this);
        binding.chat.setOnClickListener(this);
        binding.companyChat.setOnClickListener(this);
        binding.callPhoneTab.setOnClickListener(this);
        binding.rightBtn.setOnClickListener(this);
        binding.companyCarInfoExpandView.setOnClickListener(this);
        binding.invoicingExpandView.setOnClickListener(this);
        if (isGeneralGoods) {
            binding.clStatus.setVisibility(View.GONE);
            binding.clStatusGeneral.setVisibility(View.VISIBLE);
        } else {
            binding.clStatus.setVisibility(View.VISIBLE);
            binding.clStatusGeneral.setVisibility(View.GONE);
        }

        viewModel.detailsLiveData.observe(this, offerDetailsEntity -> fillData(offerDetailsEntity));
        viewModel.refreshLiveData.observe(this, aBoolean -> agreeOfferRefresh());

        viewModel.ldAgree.observe(this, a -> agreeOfferRefresh());
    }

    private void initCarInfoWindow() {
        if (carInfoWindow == null) {
            carInfoWindow = new BottomSheetDialog(this);
            View view = LayoutInflater.from(this).inflate(R.layout.sheet_dialog_car_info, null);
            carInfoWindow.setContentView(view);
            carInfoWindow.setCancelable(true);
            carInfoWindow.setCanceledOnTouchOutside(true);

            RecyclerView rv = view.findViewById(R.id.rv_cars_info);
            rv.setLayoutManager(new LinearLayoutManager(this));
            CarInfoAdapter adapter = new CarInfoAdapter(entity.getDriverAuths());
            rv.setAdapter(adapter);

            view.findViewById(R.id.close).setOnClickListener(v -> carInfoWindow.dismiss());
        }
        carInfoWindow.show();
    }

    private void initCompanyDetailInfoWindow() {
        if (entity != null) {
            if (invoiceDialog == null) {
                invoiceDialog = new InvoiceInfoBottomDialog(getActivity(), null);
            }
            invoiceDialog.show();
            if (entity.getInvoiceInfo() != null) {
                InvoiceInfoBottomDialog.InvoiceInfo invoiceInfo = new InvoiceInfoBottomDialog.InvoiceInfo(
                        entity.getInvoiceInfo().getCompanyName(),
                        entity.getInvoiceInfo().getCreditCode(),
                        entity.getInvoiceInfo().getAddress(),
                        entity.getInvoiceInfo().getPhone(),
                        entity.getInvoiceInfo().getBank(),
                        entity.getInvoiceInfo().getBankAccount(),
                        entity.getInvoiceInfo().getBankNumber());
                invoiceDialog.setInvoiceInfo(invoiceInfo);
            }
            if (entity.getPersonalInvoiceInfo() != null) {
                InvoiceInfoBottomDialog.InvoiceInfo invoiceInfo = new InvoiceInfoBottomDialog.InvoiceInfo(
                        entity.getPersonalInvoiceInfo().getCompanyName(),
                        entity.getPersonalInvoiceInfo().getNumber(),
                        entity.getPersonalInvoiceInfo().getAddress(),
                        entity.getPersonalInvoiceInfo().getTel(),
                        entity.getPersonalInvoiceInfo().getBank(),
                        entity.getPersonalInvoiceInfo().getBankAccount(),
                        "");
                invoiceDialog.setInvoiceInfo(invoiceInfo);
            }
        }
    }

    @Override
    public void onMultiClick(View v) {
        switch (v.getId()) {
            //查看附件
            case R.id.accessory:
                SeeAttachmentActivity.Companion.start(this, attachmentImages);
                break;

            //IM
            case R.id.chat:
            case R.id.company_chat:
                if (isLogin()) {
                    if (entity != null && !TextUtils.isEmpty(entity.getImAccount())) {
                        IMUtils.getInstance().buildSingleTalking(entity.getImAccount());
//                        MToast.showToast(getActivity(), "功能暂未开放");
//                        NimUIKit.startP2PSession(this, entity.getImAccount());
                    }
                } else {
                    //需要登陆
                    VerificationCodeLoginActivity.start(OfferOwnerDetailsActivity.this);
                }
                break;

            //打电话
            case R.id.contact_number:
            case R.id.company_contact_number:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(getActivity());
                    return;
                }
                if (entity != null && !TextUtils.isEmpty(entity.getTelphone())) {
                    showCallDialog(entity.getTelphone());
                } else {
                    ToastUtil.show(getActivity(), "无联系方式");
                }
                break;


            case R.id.right_btn:
                if (entity.getOfferStatus().equals("1")) {
                    showOfferDialog();
                } else if (entity.getOfferStatus().equals("2")) {
                    if (!TextUtils.isEmpty(entity.getOrderNo())) {
                        //跳转竞价订单详情
                        BiddingOrderDetailsActivity.start(this, entity.getOrderNo(), 0);
                    }
                }
                break;

            case R.id.company_car_info_expand_view:
                initCarInfoWindow();
                break;

            case R.id.invoicing_expand_view:
                initCompanyDetailInfoWindow();
                break;
        }
    }

    private boolean isLogin() {
        return !TextUtils.isEmpty(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""));
    }

    /**
     * 展示同意报价对话框
     */
    private void showOfferDialog() {
        String name = "";
        switch (entity.getOfferType()) {
            case "1"://企业
                name = entity.getCompanyName();
                break;
            case "2"://团队
                name = entity.getTeamName();
                break;
            case "3"://个人
                name = entity.getName();
                break;
        }
        if (isGeneralGoods) {
            String content = "";
            if (NumberUtil.convertToDouble(entity.getMessagePrice()) != 0) {
                content = "下单后，承运人支付信息费后生成货运订单，您确定要下单吗？";
            } else {
                content = "下单后，将生成货运订单，您确定要下单吗？";
            }

            new RoundDialog.Builder(this)
                    .title("提示")
                    .content(content)
                    .cancel("取消")
                    .confirm("确定")
                    .contentGravity(Gravity.CENTER)
                    .cancelable(false)
                    .confirmCallback(v -> {
                        viewModel.agreeOfferGeneral(OfferOwnerDetailsActivity.this, entity.getNo(), entity.getSourceNo());
                    })
                    .show();

        } else {
            new RoundDialog.Builder(this)
                    .title("提示")
                    .content("您确定要同意" + name + "的报价吗？确定后将生成竞价订单")
                    .cancel("取消")
                    .confirm("确定")
                    .contentGravity(Gravity.CENTER)
                    .cancelable(false)
                    .confirmCallback(v -> viewModel.agreeOffer(OfferOwnerDetailsActivity.this, entity.getNo(), entity.getSourceNo()))
                    .show();


        }
    }

    /**
     * 打电话弹窗
     *
     * @param phone
     */
    public void showCallDialog(String phone) {
        new RoundDialog.Builder(this)
                .title("确认呼叫")
                .content(phone)
                .cancel("取消")
                .confirm("确定")
                .contentGravity(Gravity.CENTER)
                .cancelable(false)
                .confirmCallback(v -> callPhone(phone))
                .show();
    }

    public void fillData(OfferDetailsEntity entity) {
        if (entity == null) {
            ToastUtil.show(getActivity(), "未获取到数据信息");
            return;
        }
        this.entity = entity;
        if (isGeneralGoods) {
            binding.rlQuotePeopleInfo.setVisibility(View.GONE);
        } else {
            binding.rlQuotePeopleInfo.setVisibility(View.VISIBLE);
        }

        //1已报价  2货主已同意  3货主未同意
        //1已报价  2待支付,3已支付(货主已同意) 4超时未支付 5货主未同意
        switch (entity.getOfferStatus()) {
            case "1":
                binding.offerStatus.setText("已报价");
                binding.offerStatus.setTextColor(Color.parseColor("#5792FD"));
                binding.rightBtn.setText("下单");
                binding.llRightBtn.setVisibility(View.VISIBLE);

                binding.offerStatusGeneral.setText("已报价");
                binding.offerStatusGeneral.setTextColor(getResources().getColor(R.color.c_5792FD));
                binding.statusExplainGeneral.setText("待货主处理");
                break;

            case "2":
                binding.offerStatus.setText("报价已同意");
                binding.offerStatus.setTextColor(Color.parseColor("#06C764"));

                binding.offerStatusGeneral.setText("报价待支付");
                binding.offerStatusGeneral.setTextColor(getResources().getColor(R.color.FFC000));
                binding.statusExplainGeneral.setText("待车主支付" + NumberUtil.trim0(entity.getMessagePrice()) + "元信息费");

                if (!isGeneralGoods) {
                    binding.rightBtn.setText("查看订单");
                    binding.llRightBtn.setVisibility(View.VISIBLE);
                } else {
                    binding.llRightBtn.setVisibility(View.GONE);
                }
                break;
            case "3":
                binding.offerStatusGeneral.setText("报价已支付");
                binding.offerStatusGeneral.setTextColor(Color.parseColor("#06C764"));
                binding.statusExplainGeneral.setText("车主已支付" + NumberUtil.trim0(entity.getMessagePrice()) + "元信息费");
                binding.rightBtn.setText("查看订单");
                binding.llRightBtn.setVisibility(View.VISIBLE);
                binding.rightBtn.setOnClickListener(v -> {
                    toTransportOrderDetail(entity.getOrderNo());
                });
                break;
            case "5":
                binding.offerStatus.setText("报价未同意");
                binding.offerStatus.setTextColor(Color.parseColor("#FF2928"));
                binding.llRightBtn.setVisibility(View.GONE);

                binding.offerStatusGeneral.setText("报价已失效");
                binding.offerStatusGeneral.setTextColor(getResources().getColor(R.color.color_c0c4cc));
                String failueCause = "";
                switch (entity.getFailureCause()) {
                    case 0:
                        failueCause = "承运方超时未支付信息费";
                        break;
                    case 1:
                        failueCause = "货主未同意报价";
                        break;
                    case 2:
                        failueCause = "货主已下架货源";
                        break;
                    case 3:
                        failueCause = "货主已删除货源";
                        break;
                }
                binding.statusExplainGeneral.setText(failueCause);
                break;
            case "4":
                binding.offerStatus.setText("报价已失效");
                binding.offerStatus.setTextColor(Color.parseColor("#C0C4CC"));
                binding.llRightBtn.setVisibility(View.GONE);
                binding.offerStatusGeneral.setText("报价已失效");
                binding.offerStatusGeneral.setTextColor(getResources().getColor(R.color.color_c0c4cc));
                String failueCause1 = "";
                switch (entity.getFailureCause()) {
                    case 0:
                        failueCause1 = "承运方超时未支付信息费";
                        break;
                    case 1:
                        failueCause1 = "货主未同意报价";
                        break;
                    case 2:
                        failueCause1 = "货主已下架货源";
                        break;
                    case 3:
                        failueCause1 = "货主已删除货源";
                        break;
                }
                binding.statusExplainGeneral.setText(failueCause1);
                break;
        }

        RequestOptions requestOptions = null;
        if (!TextUtils.isEmpty(entity.getOfferType())) {
            switch (entity.getOfferType()) {
                case "1"://企业
                    if (!isGeneralGoods) {
                        binding.companyInfoLayout.setVisibility(View.VISIBLE);
                    }
                    binding.companyName.setText(!TextUtils.isEmpty(entity.getCompanyName()) ? entity.getCompanyName() : "/");
                    binding.offerArticle.setText(!TextUtils.isEmpty(entity.getCompanyName()) ? entity.getCompanyName() : "");
                    binding.creditCode.setText(!TextUtils.isEmpty(entity.getCreditCode()) ? entity.getCreditCode() : "/");
                    binding.companyType.setText(!TextUtils.isEmpty(entity.getCompanyType()) ? entity.getCompanyType() : "/");
                    binding.registeredAssets.setText(!TextUtils.isEmpty(entity.getRegisteredCapital()) ? entity.getRegisteredCapital() + "元" : "/");
                    binding.setUpDate.setText(!TextUtils.isEmpty(entity.getEstablishmentDate()) ? DateUtils.formatDate(entity.getEstablishmentDate(), "yyyy-MM-dd") : "/");
                    binding.companyAddress.setText(!TextUtils.isEmpty(entity.getBusinessAddress()) ? entity.getBusinessAddress() : "/");
                    binding.carInfo.setVisibility(View.GONE);
                    binding.carInfoHint.setVisibility(View.GONE);
                    binding.carLocation.setVisibility(View.GONE);
                    binding.carLocationHint.setVisibility(View.GONE);

                    binding.companyLayout.setVisibility(View.VISIBLE);
                    binding.driverLayout.setVisibility(View.GONE);

                    requestOptions = new RequestOptions()
                            .placeholder(R.mipmap.icon_company_default)
                            .fallback(R.mipmap.icon_company_default)
                            .error(R.mipmap.icon_company_default);
                    break;

                case "2"://团队
                    if (!isGeneralGoods) {
                        binding.teamInfoLayout.setVisibility(View.VISIBLE);
                    }
                    binding.teamName.setText(!TextUtils.isEmpty(entity.getTeamName()) ? entity.getTeamName() : "/");
                    binding.offerArticle.setText(!TextUtils.isEmpty(entity.getTeamName()) ? entity.getTeamName() : "");
                    binding.teamBusiness.setText(!TextUtils.isEmpty(entity.getBusinessTypeNo()) ? entity.getBusinessTypeNo() : "/");
                    binding.teamPeopleNum.setText(entity.getScale() + "人");
                    binding.teamAddress.setText(!TextUtils.isEmpty(entity.getBusinessAddress()) ? entity.getBusinessAddress() : "/");
                    binding.carInfo.setVisibility(View.GONE);
                    binding.carInfoHint.setVisibility(View.GONE);
                    binding.carLocation.setVisibility(View.GONE);
                    binding.carLocationHint.setVisibility(View.GONE);

                    binding.companyLayout.setVisibility(View.VISIBLE);
                    binding.driverLayout.setVisibility(View.GONE);

                    requestOptions = new RequestOptions()
                            .placeholder(R.mipmap.icon_team_default_1)
                            .fallback(R.mipmap.icon_team_default_1)
                            .error(R.mipmap.icon_team_default_1);
                    break;

                case "3"://个人
                    binding.companyLayout.setVisibility(View.GONE);
                    binding.driverLayout.setVisibility(View.VISIBLE);
                    binding.offerArticle.setText(!TextUtils.isEmpty(entity.getName()) ? entity.getName() : "");

                    binding.carLocation.setVisibility(View.VISIBLE);
                    binding.carLocationHint.setVisibility(View.VISIBLE);

                    requestOptions = new RequestOptions()
                            .placeholder(R.drawable.geren_person_touxiang)
                            .fallback(R.drawable.geren_person_touxiang)
                            .error(R.drawable.geren_person_touxiang);
                    break;
            }
        }

        /**
         * 报价单位信息
         */
        Glide.with(getActivity())
                .load(entity.getHeadImage())
                .apply(requestOptions)
                .into(binding.head);

        if (!TextUtils.isEmpty(entity.getName()) && "3".equals(entity.getOfferType())) {
            binding.name.setText(entity.getName() + "(司机)");
        } else {
            binding.name.setText(entity.getName());
        }

        if (!TextUtils.isEmpty(entity.getTelphone())) {
            binding.phoneNum.setText(entity.getTelphone());
            binding.phoneNum.setOnClickListener(view -> showCallDialog(entity.getTelphone()));
        }

        ///////////////////////货源信息
        if (entity.getPlace() != null) {
            OfferGoodsSourcePlaceEntity placeEntity = entity.getPlace();
            //发货起始地
            String addStr = "";
            if (!TextUtils.isEmpty(placeEntity.getCityName())) {
                addStr += placeEntity.getCityName() + " ";
            }
            if (!TextUtils.isEmpty(placeEntity.getDistrictName())) {
                addStr += placeEntity.getDistrictName() + " → ";
            } else {
                addStr += " → ";
            }
            if (!TextUtils.isEmpty(placeEntity.getDestCityName())) {
                addStr += placeEntity.getDestCityName() + " ";
            }
            if (!TextUtils.isEmpty(placeEntity.getDestDistrictName())) {
                addStr += placeEntity.getDestDistrictName();
            }
            binding.transportPath.setText(addStr);

            //运程
            if (!TextUtils.isEmpty(placeEntity.getTotalDistance())) {
                if (Double.valueOf(placeEntity.getTotalDistance()) < 1000) {
                    binding.haul.setText("运程：1km以内");
                } else {
                    binding.haul.setText(String.format("运程：约%skm", StringUtil.fromatUpDistance(placeEntity.getTotalDistance()) + ""));
                }
            }
        }

        String goodsInfo = "";
        if (!TextUtils.isEmpty(entity.getGoodsTypeName())) {
            goodsInfo += entity.getGoodsTypeName();
        }
        if (!TextUtils.isEmpty(entity.getSecondGoodsTypeName())) {
            goodsInfo += "/" + entity.getSecondGoodsTypeName();
        }
        if (!TextUtils.isEmpty(entity.getWeight())) {
            goodsInfo += NumberUtil.trim0(entity.getWeight()) + "吨 ";
        }
        if (!TextUtils.isEmpty(entity.getVolume())) {
            goodsInfo += NumberUtil.trim0(entity.getVolume()) + "方";
        }
        if (!TextUtils.isEmpty(goodsInfo)) {
            binding.goodsInfo.setText(goodsInfo);
        }

        if (!TextUtils.isEmpty(entity.getSourceAllFreight())) {
            binding.freightPrice.setText(NumberUtil.trim0(entity.getSourceAllFreight()) + "元");
        }

        //司机报价信息
        if (!TextUtils.isEmpty(entity.getCreateTime())) {
            binding.offerTime.setText(DateUtils.formatDate(String.valueOf(entity.getCreateTime()), ""));
        }

//        if (isGeneralGoods) {
//            binding.freightOffer.setText(!TextUtils.isEmpty(entity.getAllFreight()) ? NumberUtil.trim0(entity.getAllFreight()) + "元" : "/");
//        } else {
//            binding.freightOffer.setText(!TextUtils.isEmpty(entity.getFreight()) ? NumberUtil.trim0(entity.getFreight()) + "元/吨" : "/");
//        }

        binding.freightOffer.setText(
                !TextUtils.isEmpty(entity.getFreight())
                        ? "单价" + NumberUtil.trim0(entity.getFreight()) + entity.getQuotationFreightUnit()
                        : "/");
        binding.freightOfferAll.setText(
                !TextUtils.isEmpty(entity.getAllFreight())
                        ? NumberUtil.trim0(entity.getAllFreight()) + "元"
                        : "/");

        //车辆位置
        String address = "";
//                    if (!TextUtils.isEmpty(entity.getProvinceName()))
//                        address += entity.getProvinceName();
//                    if (!TextUtils.isEmpty(entity.getCityName()))
//                        address += entity.getCityName();
//                    if (!TextUtils.isEmpty(entity.getDistrictName()))
//                        address += entity.getDistrictName();
        if (!TextUtils.isEmpty(entity.getDetailAddress()))
            address += entity.getDetailAddress();
        binding.carLocation.setText(!TextUtils.isEmpty(address) ? address : "/");
        binding.address.setText(!TextUtils.isEmpty(address) ? address : "/");

        if (!TextUtils.isEmpty(entity.getMarketingPublicity())) {
            binding.promotion.setText(entity.getMarketingPublicity());
        } else {
            binding.promotionLayout.setVisibility(View.GONE);
        }

        //车辆信息
        String carInfo = "";
        if (entity.getDriverAuths() != null && entity.getDriverAuths().size() >= 1) {
            for (int i = 0; i < entity.getDriverAuths().size(); i++) {
                carInfo += entity.getDriverAuths().get(i).getCarNumber() + " ";
            }
            if ("3".equals(entity.getOfferType())) {
                if (!TextUtils.isEmpty(entity.getDriverAuths().get(0).getCarTypeName()))
                    carInfo += entity.getDriverAuths().get(0).getCarTypeName() + " ";
                if (!TextUtils.isEmpty(entity.getDriverAuths().get(0).getCarLenName()))
                    carInfo += "长" + entity.getDriverAuths().get(0).getCarLenName() + " ";
                //栏高
                if (!TextUtils.isEmpty(entity.getDriverAuths().get(0).getHeightHurdle()))
                    carInfo += "栏高" + NumberUtil.trim0(entity.getDriverAuths().get(0).getHeightHurdle()) + "米 ";
            }
        }

        if (!TextUtils.isEmpty(carInfo)) {
            binding.carInfo.setVisibility(View.VISIBLE);
            binding.carInfoHint.setVisibility(View.VISIBLE);
            binding.carInfo.setText(StringUtil.removeChar(carInfo, "/"));
            binding.companyCarInfo.setText(carInfo);
            binding.companyCarInfoExpandView.setVisibility( View.VISIBLE);
        } else {
            binding.carInfo.setVisibility(View.GONE);
            binding.carInfoHint.setVisibility(View.GONE);
            binding.companyCarInfo.setText("/");
            binding.companyCarInfoExpandView.setVisibility( View.GONE);
        }
        binding.invoicingLayout.setVisibility(entity.getInvoiceInfo() == null && entity.getPersonalInvoiceInfo() == null ? View.GONE : View.VISIBLE);
        if (entity.getPersonalInvoiceInfo() != null) {
            binding.invoicingContentView.setText(entity.getPersonalInvoiceInfo().getCompanyName());
        }
        if (entity.getInvoiceInfo() != null) {
            binding.invoicingContentView.setText(entity.getInvoiceInfo().getCompanyName());
        }

        if (isGeneralGoods) {
            if (NumberUtil.convertToDouble(entity.getMessagePrice()) != 0) {
                binding.freightUnitHint.setText("信息费");
                binding.freightUnit.setText(!TextUtils.isEmpty(entity.getMessagePrice()) ? NumberUtil.trim0(entity.getMessagePrice()) + "元" : "/");
            } else {
                binding.freightUnitHint.setVisibility(View.GONE);
                binding.freightUnit.setVisibility(View.GONE);
            }
            binding.freightPrice.setText(entity.getFreightType() == null || entity.getFreightType() == 0 ?
                    !TextUtils.isEmpty(entity.getSourceAllFreight()) ? NumberUtil.trim0(entity.getSourceAllFreight()) + "元" : "/" : "电议");
        } else {
            binding.freightUnit.setText(!TextUtils.isEmpty(entity.getSourceFreight()) ? NumberUtil.trim0(entity.getSourceFreight()) + entity.getFreightUnit() : "/");
            binding.freightPrice.setText(!TextUtils.isEmpty(entity.getSourceAllFreight()) ? NumberUtil.trim0(entity.getSourceAllFreight()) + "元" : "/");
        }

        binding.contactInfo.setText(!TextUtils.isEmpty(entity.getContrcts()) ? entity.getContrcts() + "  " : "");
        binding.companyContactInfo.setText(!TextUtils.isEmpty(entity.getContrcts()) ? entity.getContrcts() + "  " : "");
        if (!TextUtils.isEmpty(entity.getContrctsNumber())) {
            binding.contactNumber.setText(entity.getContrctsNumber());
            binding.companyContactNumber.setText(entity.getContrctsNumber());
            binding.contactNumber.setOnClickListener(view -> showCallDialog(entity.getContrctsNumber()));
            binding.companyContactNumber.setOnClickListener(view -> showCallDialog(entity.getContrctsNumber()));
        }


        if (!TextUtils.isEmpty(entity.getNote())) {
            binding.remarkLayout.setVisibility(View.VISIBLE);
            binding.contentView.setText(entity.getNote());
            new ExpandedTextView().showTextPick(binding.contentView, binding.expandView);
        } else {
            binding.remarkLayout.setVisibility(View.GONE);
        }

        if (entity.getDiyField() != null && entity.getDiyField().size() > 0) {
            binding.customContent.setVisibility(View.VISIBLE);
            binding.customContent.removeAllViews();
            for (int i = 0; i < entity.getDiyField().size(); i++) {
                AddField itemEntity = entity.getDiyField().get(i);
                if (!TextUtils.isEmpty(itemEntity.getValue()))
                    addCustomLayout(binding.customContent, itemEntity);
            }
        } else {
            binding.customContent.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(entity.getAccessory())) {
            List<String> images = Arrays.asList(entity.getAccessory().split(","));
            attachmentImages = new ArrayList<>(images);
        } else {
            attachmentImages = new ArrayList();
        }

        if (attachmentImages.size() == 0) {
            binding.accessoryHint.setVisibility(View.GONE);
            binding.accessory.setVisibility(View.GONE);
        } else {
            binding.accessoryHint.setVisibility(View.VISIBLE);
            binding.accessory.setVisibility(View.VISIBLE);
        }
        binding.accessory.setOnClickListener(this::onMultiClick);

        String inTime = DateUtils.stampToDay5(entity.getInTime());
        binding.arriveTime.setText(TextUtils.isEmpty(inTime) ? "/" : inTime);
        binding.companyArriveTime.setText(TextUtils.isEmpty(inTime) ? "/" : inTime);

        binding.scrollView.setVisibility(View.VISIBLE);
        binding.bottomBar.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timeCount != null)
            timeCount.cancel();
    }

    /**
     * 为自定义字段添加布局
     *
     * @param content
     * @param entity
     */
    private void addCustomLayout(LinearLayout content, AddField entity) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.custom_field_layout, null);
        TextView remark_hint = view.findViewById(R.id.remark_hint);
        TextView content_tv = view.findViewById(R.id.content_tv);
        TextView expand_tv = view.findViewById(R.id.expand_tv);
        if (!TextUtils.isEmpty(entity.getKey())) {
            remark_hint.setText(entity.getKey());
        } else
            remark_hint.setText("自定义");

        content_tv.setText(entity.getValue());
        new ExpandedTextView().showTextPick(content_tv, expand_tv);
        content.addView(view);
    }

    @Override
    protected void onResume() {
        super.onResume();
        viewModel.getOfferOwnerDetails(this, offerNo);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
//        DaggerSelfComponent.builder()
//                .appComponent(appComponent)
//                .selfModule(new SelfModule(this))
//                .build().inject(this);

    }

//    @Override
//    public void countdown(int days, int hours, int minutes, int seconds) {
//        if (days == 0 && hours == 0 && minutes == 0 && seconds == 0) {
//            binding.offerStatus.setText("车主超时未支付信息费");
//            binding.offerStatus.setTextColor(getResources().getColor(R.color.c_FF4B10));
//            binding.countDownLay.setVisibility(View.GONE);
//        } else {
//            String timeStr = "";
//            if (days > 0)
//                timeStr += days + "天";
//            if (hours >= 0)
//                timeStr += hours + "时";
//            if (minutes >= 0)
//                timeStr += minutes + "分";
//            if (seconds >= 0)
//                timeStr += seconds + "秒";
//            binding.timeCountDown.setText(timeStr);
//        }
//    }

    /**
     * 查看货运订单详情
     */
    private void toTransportOrderDetail(String orderNo) {
        ActivityJump.jumpToActivity(this, TransportOrderDetailOwnerActivity.class, Pair.create("no", orderNo),
                Pair.create("isGoodsOwner", TransportOrderDetailOwnerActivity.GOODS_OWNER));
    }

    /**
     * 货主同意同意报价
     */
    public void agreeOfferRefresh() {
        viewModel.getOfferOwnerDetails(this, offerNo);
        EventBus.getDefault().post(LogisticsEvent.make().setMessageTag(EventConstant.EVENT_REFRESH_OFFER_OWNER_PAGE));
        EventBus.getDefault().post(LogisticsEvent.make(EventConstant.EVENT_GOODS_AGREED_OFFER, null));
    }
}
